package educationaladministrationsystem.CSM.Mapper.Service.Root;

import educationaladministrationsystem.CSM.Mapper.Service.ServiceInterface.RootInterface.RootCount;
import educationaladministrationsystem.Class.Count;
import educationaladministrationsystem.CSM.Mapper.Root.RootCountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RootCountService implements RootCount {
    @Autowired
    private RootCountMapper rootCountMapper;

    @Override
    public List<Count> getAllCount(int page, int pageNumber) {
        return rootCountMapper.getAllCount((page - 1) * pageNumber, pageNumber);
    }

    @Override
    public List<Count> getSearchCount(int page, int pageNumber, String information) {
        return rootCountMapper.getSearchCount((page - 1) * pageNumber, pageNumber, information);
    }

    @Override
    public Count getUpdateCountInformation(String id) {
        return rootCountMapper.getUpdateCountInformation(id);
    }

    @Override
    public void updateCount(String countNumber, String newPassword) {
        rootCountMapper.updateCount(countNumber, newPassword);
    }

    @Override
    public int getPage(int pageNumber) {
        double all = rootCountMapper.getPage();
        return (int) Math.ceil(all / pageNumber);
    }
}
